<template>
    <div class="editor-page">
  <div class="container page">
    <div class="row">

      <div class="col-md-10 offset-md-1 col-xs-12">
        <form>
          <fieldset>
            <fieldset class="form-group">
                <input type="text" class="form-control form-control-lg" placeholder="Article Title" v-model="article.title">
            </fieldset>
            <fieldset class="form-group">
                <input type="text" class="form-control" placeholder="What's this article about?"  v-model="article.description">
            </fieldset>
            <fieldset class="form-group">
                <textarea class="form-control" rows="8" placeholder="Write your article (in markdown)"  v-model="article.body"></textarea>
            </fieldset>
            <fieldset class="form-group">
                <input type="text" class="form-control" placeholder="Enter tags"><div class="tag-list"  v-model="article.tagList"></div>
            </fieldset>
            <button class="btn btn-lg pull-xs-right btn-primary" type="button" @click="onSubmit">
                Publish Article
            </button>
          </fieldset>
        </form>
      </div>

    </div>
  </div>
</div>
</template>
<script>
import { createArticle } from '@/api/article'
export default {
  // middleware,在匹配路由渲染之前先执行中间件，多个用数组，单个可用字符串
    middleware: 'authenticated',
    name:'EditorIndex',
    data(){
        return {
          "article": {
            "title": "",
            "description": "",
            "body": "",
            "tagList": ''
          }
        }
    },
    methods:{
        async onSubmit(){
          try {
            const { data } =  await createArticle({
              article:this.article
            })
            alert('创建成功')
            // this.$router.push('/')

          } catch (error) {
            this.errors = error.response.data.errors
          }
            
        },
    }
}
</script>